<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加终端资产</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">部门</label>
                <div class="layui-input-block">
                    <input type="text" name="Department"  placeholder="请输入部门" class="layui-input" id="PcDepartmentSelect">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">二级部门</label>
                <div class="layui-input-block">
                    <input type="text" name="DepartmentSub" placeholder="请输入二级部门" class="layui-input" id="PcDepartmentSubSelect">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">员工姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="PersonName" placeholder="请输入员工姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-block">
                    <input type="text" name="WorkNumber" placeholder="请输入员工工号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">计算机类型</label>
                <div class="layui-input-block">
                    <select name="ComputerType" lay-verify="">
                        <option value="台式机" selected>台式机</option>
                        <option value="笔记本">笔记本</option>
                        <option value="其他设备">其他设备</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">计算机名</label>
                <div class="layui-input-block">
                    <input type="text" name="ComputerName" placeholder="请输入员工计算机名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">IP/MAC地址</label>
                <div class="layui-input-block">
                    <textarea name="Address" id="Address" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">涉密等级</label>
                <div class="layui-input-block">
                    <select name="SecretLevel" lay-verify="">
                        <option value="普通商密" selected>普通商密</option>
                        <option value="核心商密">核心商密</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">互联网权限</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="InternetFlag" lay-skin="switch" lay-text="是|否" value="是">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">USB文件拷贝权限</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="FileCopyFlag" lay-skin="switch" lay-text="是|否" value="是">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">外网邮箱权限</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="EmailFlag" lay-skin="switch" lay-text="是|否" value="是">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">VPN权限</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="VpnFlag" lay-skin="switch" lay-text="是|否" value="是">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">PDM权限</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="PdmFlag" lay-skin="switch" lay-text="是|否" value="是">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="PublicIp" id="Remarks" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="assets_type_add">确认添加</button>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['form', 'tableSelect'], function () {
        var $ = layui.jquery,
            form = layui.form,
            tableSelect = layui.tableSelect;

        //监听提交
        form.on('submit(assets_type_add)', function(data) {
            $.ajax({
                url: "/api/assets/pc",
                data: JSON.stringify(data.field),
                contentType: 'application/json;charset=UTF-8',
                dataType: 'json',
                type: 'put',
                success: function(result) {
                    if (result.code == 200) {
                        var index = layer.alert("添加资产信息成功", {
                            title: '提示',
                            icon: 1
                        }, function() {
                            parent.layui.table.reload("currentTable_AssetsPc");
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        })
                    } else {
                        layer.alert(result.msg, {
                            title: '提示',
                            icon: 2
                        })
                    }
                },
                error: function (e) {
                    layer.alert(JSON.stringify(e), {title: '提示', icon: 2})
                }
            })
            return false;
        });

        tableSelect.render({
            elem: '#PcDepartmentSelect',
            checkedKey: 'id',
            searchPlaceholder: '部门搜索',
            searchKey: 'Department',
            table: {
                url: '/api/assets/group/pc/department',
                cols: [[
                    {type: 'radio', title: "选择"},
                    {field: 'id', width: 60, title: 'ID'},
                    {field: 'department', title: '部门'},
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.department)
                })
                elem.val(NEWJSON.join(","))
            }
        })

        tableSelect.render({
            elem: '#PcDepartmentSubSelect',
            checkedKey: 'id',
            searchPlaceholder: '二级部门搜索',
            searchKey: 'DepartmentSub',
            table: {
                url: '/api/assets/group/pc/departmentsub',
                cols: [[
                    {type: 'radio', title: "选择"},
                    {field: 'id', width: 60, title: 'ID'},
                    {field: 'department_sub', title: '二级部门'},
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.department_sub)
                })
                elem.val(NEWJSON.join(","))
            }
        })
    });
</script>

</body>
</html>
